package com.yzy.util;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseCode<T> implements Serializable {
    //状态码， 1：成功  0：失败   2：处理中
    private Integer code;
    //描述信息
    private String msg;
    //数据
    private T data;


    private ResponseCode(Integer code, T data, String msg ){
        this.code=code;
        this.msg=msg;
        this.data=data;
    }

    //成功
    public static ResponseCode buildeSuccess(){
        return new ResponseCode(200,null,null);
    }
    //成功， 传描述信息
    public static ResponseCode buildSuccess(String msg){
        return new ResponseCode(200,null,msg);
    }
    //成功， 传数据
    public static<T> ResponseCode<T> buildSuccess(T data){
        return new ResponseCode(200,data,null);
    }
    //成功， 传数据和描述信息
    public static<T> ResponseCode<T> buildSuccess(T data,String msg){
        return new ResponseCode(200,data,msg);
    }

    //失败
    public static ResponseCode buildFailed(){
        return new ResponseCode(500,null,null);
    }
    //失败 传描述信息
    public static ResponseCode buildFailed(String msg){
        return new ResponseCode(500,null,msg);
    }

    //失败 自定义状态码
    public static ResponseCode buildFailed(Integer code,String msg){
        return new ResponseCode(code,null,msg);
    }
}
